<!-- 添加或修改班级信息 -->
<template>
  <div class="clazz-detail-min">
    <el-dialog
      title="班级信息--编辑"
      :visible.sync="dialogVisible"
      width="70%"
      :before-close="handleClose"
    >
      <el-card shadow="never">
        <div slot="header">
          <span>班级基本信息</span>
        </div>
        <el-form ref="from" :model="clazz" label-width="80px">
          <el-form-item label="班级名称">
            <el-input v-model="clazz.className"></el-input>
          </el-form-item>
          <el-form-item label="班级类型">
            <el-select v-model="clazz.type" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开班时间">
            <el-date-picker
              v-model="clazz.startTime"
              type="date"
              placeholder="开班日期"
              value-format="yyyy-MM-dd-HH-mm-ss"
              width="200"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="结课时间">
            <el-date-picker
              v-model="clazz.endTime"
              type="date"
              placeholder="结课日期"
              value-format="yyyy-MM-dd"
              width="200"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="班级描述">
            <el-input v-model="clazz.desc" type="textarea"></el-input>
          </el-form-item>
        </el-form>
      </el-card>

      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="doSave">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { classSave, classUpdate, classDetail } from "@/api/system/clazz";
export default {
  data() {
    return {
      dialogVisible: false,
      clazz: {},
      options: [
        {
          value: "0",
          label: "前端",
        },
        {
          value: "1",
          label: "ui",
        },
      ],
    };
  },
  created() {},
  methods: {
    handleClose() {
      this.dialogVisible = false;
      this.clazz = {};
    },
    openDialog() {
      this.dialogVisible = true;
    },
    openDialogShow(id) {
      this.openDialog(),
        classDetail({ id }).then((res) => {
          this.clazz = res.data;
        });
    },
    doSave() {
      var api = null;
      if (this.clazz.id) {
        api = classUpdate;         
      } else {
        api = classSave;    
      }
      api({
        xyClassInfo: {
          ...this.clazz,
        },
      }).then((res) => {
        if (res.code == "error") {
          this.$message.error("保存数据失败");
        } else {
          this.$message.success("保存成功"),
          this.$emit("resfrsh-list"),
          this.handleClose();
        }
      });
    },
  },
};
</script>
<style lang='scss' scoped>
.el-card {
  border: none;
}
</style>